summaryrefslogtreecommitdiff
path: root/website/src/pages/microlog/[...slug].astro
blob: 69c94b0867f12ecc1451204351c0a9f5ffd5430c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
import { type CollectionEntry, getCollection, render } from 'astro:content';
import MicrologPost from '../../layouts/MicrologPost.astro';
import { renderGemtextToHtml } from '../../renderGemtextToHtml';

export async function getStaticPaths() {
	const posts = await getCollection('microlog');
	return posts.map((post) => ({
		params: { slug: post.id },
		props: post,
	}));
}
type Props = CollectionEntry<'microlog'>;

const { id: slug, body } = Astro.props;
const pubDateStr = slug.replaceAll(/\.[0-9]+/g, '');
const pubDate = new Date(pubDateStr);
if (isNaN(pubDate.valueOf())) {
  throw new Error(`Could not construct a valid publication date for microlog post: ${slug}`);
}
const Content = renderGemtextToHtml(body ?? '', pubDateStr);
---

<MicrologPost pubDate={pubDate} title={pubDateStr}>
  <Fragment set:html={Content}></Fragment>
</MicrologPost>